import asyncio
import time

async def say_after(delay, what):
    await asyncio.sleep(delay)
    print(what)

async def long_time_job(n, content):
    for i in range(n):
        await asyncio.sleep(1)
        print('{0} from long time job ...'.format(content))

async def main():
    print(f"started at {time.strftime('%X')}")
    # task1 = asyncio.create_task(say_after(1, 'hello'))
    # task2 = asyncio.create_task(say_after(2, 'world'))
    # await task2
    # await task1

    # # sequential
    # await long_time_job(5, 'first')
    # await long_time_job(3, 'second')

    # concurrent
    task1 = asyncio.create_task(long_time_job(5,'first'))
    task2 = asyncio.create_task(long_time_job(3,'second'))
    # await asyncio.sleep(6)
    # await task1
    # await asyncio.sleep(1)
    await task2

    # # concurrent
    # task1 = asyncio.create_task(long_time_job(5, 'first'))
    # task2 = asyncio.create_task(long_time_job(3, 'second'))
    # await asyncio.gather(task1,task2)

    print(f"finished at {time.strftime('%X')}")

asyncio.run(main())
